<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
</head>

<body>
    <script type="text/javascript">
        // 寄生组合式继承

        function inheritObject(o) {
            function F() {}
            F.prototype = o
            console.log(F)
                // var ox=new F()
            return new F()
        }

        function inheritPro(subClass, superClass) {
            var p=inheritObject(superClass.prototype)
            // var p = Object.create(superClass.prototype)
            p.constructor = subClass
            subClass.prototype = p
        }

        function createBook(obj) {
            var o = inheritObject(obj)
            o.getName = function() {
                console.log(this.name)
            }
            return o;
        }

        function SuperClass(id) {
            this.book = ['1', '2', '3']
            this.id = id
        }
        SuperClass.prototype.showbook = function() {
            console.log(this.book)
        }

        function SubClass(id, time) {
            SuperClass.call(this, id)
            this.time = time
        }




        inheritPro(SubClass, SuperClass)
        SubClass.prototype.getTime = function() {
            console.log(this.time)
        }
        var instance = new SubClass(1, 3)
        var instance2 = new SubClass(2, 4)
        console.log(SubClass.prototype.constructor)
        instance.book.push('4')
        instance.showbook()
        instance2.showbook()
            // instance2.showbook()
    </script>
</body>

</html>